package com.caicai.mapper;

import cmo.caicai.service.UserInfoService;
import com.caicai.domain.User;
import net.bytebuddy.implementation.bytecode.Throw;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Component
public class UserInfoMapper implements UserInfoService {
	@Autowired
	private SqlSessionFactory  sqlSessionFactory;
	@Override
	public User findById(String id) {
		return sqlSessionFactory.openSession().selectOne("com.caicai.mapper.UserMapper.objectshow", id);
	}

	@Override
	public Object save(User user) {
		return sqlSessionFactory.openSession().insert("com.caicai.mapper.UserMapper.insert",user);
	}

	@Override
	@Transactional
	public Object saveList(List<User> users) {
		for(int i=0;i<users.size();i++){
			User user=users.get(i);
			SqlSession sqlSession=sqlSessionFactory.openSession(true);
			sqlSession.insert("com.caicai.mapper.UserMapper.insert",user);
		}
		if(true){
			throw new RuntimeException();
		}

		return null;
	}


}
